<?php

namespace App\Morefun\Quiz;

use App\Contracts\Repositories\Quiz\PaperRepository as PaperRepositoryContract;
use App\Entities\Quiz;
use App\Entities\QuizPaper;

class PaperRepository implements PaperRepositoryContract
{
    public function create(array $data)
    {
        $paper = new QuizPaper();
        $paper->fill($data);
        $paper->save();

        return $paper->id;
    }

    public function find($id, array $columns = ['*'])
    {
        return QuizPaper::query()->where('id', $id)->first($columns);
    }

    public function findWithPaginate($perPage, array $conditions, array $columns = ['*'])
    {
        return QuizPaper::query()->select($columns)->where($conditions)->paginate($perPage);
    }

    public function getEffectiveTotal($activityId)
    {
        return QuizPaper::query()->where('activity_id', $activityId)->count();
    }

    public function delete($id)
    {
        return !!QuizPaper::destroy($id);
    }

    public function count(array $conditions, $columns = '*')
    {
        return QuizPaper::query()->where($conditions)->count($columns);
    }
}
